#include <iostream>
#include <vector>
using namespace std;
#define int long long
vector<int> a;
signed main() {
    int n, x;
    cin >> n >> x;
    for(int i = 0; i < n; i++)
    {
        int t;
        cin >> t;
        a.push_back(t);
    }
    int ans = 0;
    for(int i = 1; i < n; i++) {
        int t = a[i] + a[i - 1];
        if(t > x) {
            a[i] -= (t - x);
            ans += (t - x);
            if(a[i] < 0) {
                a[i] = 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}